<?php

class ConfigAttributes_Model extends Model {

    public function __construct(){
        parent::__construct();
    }

    public function getAttributes () {
        $query = "SELECT * FROM attribute";
        return $this->_db->select ($query);
    }
    
    public function getAttribute ($id) {
        if (isset ($id)) {
            $query = "SELECT * FROM attribute WHERE id = $id";
            return $this->_db->select ($query);
        }
        return null;
    }
    
    public function addAttribute ($name, $type, $defaultValue) {
        $params = Array();
        $params['name'] = $name;
        $params['type'] = $type;
        $params['defaultValue'] = $defaultValue;
        $this->_db->insert ('attribute', $params);
        
        return true;
    }
    
    public function modifyAttribute ($id, $name, $type, $defaultValue) {
        $params = Array();
        $where = Array();
        $params['name'] = $name;
        $params['type'] = $type;
        $params['defaultValue'] = $defaultValue;
        $where['id'] = $id;
        $this->_db->update ('attribute', $params, $where);
        
        return true;
    }
    
    public function removeAttribute ($id) {
        $this->_db->delete ('attribute', 'id = ' . $id);
        
        return true;
    }
}

?>
